<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>24小时-自选池</title>
    <link rel="shortcut icon" href="favicon.ico">
    <link href="/css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
    <link href="/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">

    <link href="/css/animate.min.css" rel="stylesheet">
    <link href="/css/style.min.css?v=4.0.0" rel="stylesheet"><base target="_blank">
    <!-- Sweet Alert -->
    <link href="/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <!-- 弹窗-->
    <script src="../../tanchuan/js/jquery-2.0.0.min.js"></script>
    <link href="../../tanchuan/css/displaystyle.css" rel="stylesheet" />
    <script src="../../tanchuan/js/syntaxhighlighter_3.0.83/shCore.js"></script>
    <script src="../../tanchuan/js/syntaxhighlighter_3.0.83/shBrushJScript.js"></script>
    <link href="../../tanchuan/js/syntaxhighlighter_3.0.83/styles/shCoreRDark.css" rel="stylesheet" />
    <script src="../../tanchuan/js/NZ-Plugin/Js/NZ-Window.min.js"></script>
    <link href="../../tanchuan/js/NZ-Plugin/Css/NZ-Window.min.css" rel="stylesheet" />
    <script src="../../tanchuan/js/NZ-Plugin/Js/NZ-Drag.min.js"></script>
    <script src="/js/bootstrap.min.js?v=3.3.5"></script>
    <script src="/js/plugins/sparkline/jquery.sparkline.min.js"></script>
    <script src="/js/plugins/peity/jquery.peity.min.js"></script>
    <script src="/js/content.min.js?v=1.0.0"></script>
    <script src="/js/demo/peity-demo.min.js"></script>
    <script src="/js/plugins/gritter/jquery.gritter.min.js"></script>
    <script src="/js/plugins/sweetalert/sweetalert.min.js"></script>
</head>
<style>
</style>
<body class="gray-bg" >
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
            <div class="ibox">
                <div class="ibox-content" >
                    <h3>自选池</h3>
                    <!--                        <p class="small"><i class="fa fa-hand-o-up"></i> 输入股票代码添加新关注代码</p>-->
                    <div class="input-group">
                        <input type="text" id="codeName" placeholder="添加新股票" class="input input-sm form-control">
                        <span class="input-group-btn">
                                        <button type="button" class="btn btn-sm btn-white" onclick="handleClick()">
                                            <i class="fa fa-plus" onclick="handleClick()"></i> 添加</button>
                                </span>
                    </div>
                </div>
            </div>
    </div>
    <form id="form1" method="post" action="/addStock">
        <input type="hidden" id="addCode" name="code" value="">
        <input type="hidden" id="addDesc" name="desc" value="">
    </form>
</div>
<!--    <script src="/js/jquery.min.js?v=2.1.4"></script>-->
<script src="/js/bootstrap.min.js?v=3.3.5"></script>
<script src="/js/plugins/sparkline/jquery.sparkline.min.js"></script>
<script src="/js/plugins/peity/jquery.peity.min.js"></script>
<script src="/js/content.min.js?v=1.0.0"></script>
<script src="/js/demo/peity-demo.min.js"></script>
<script src="/js/plugins/gritter/jquery.gritter.min.js"></script>
<script src="/js/plugins/sweetalert/sweetalert.min.js"></script>
<script  th:inline="javascript">
    /**
     * 添加
     * */
    function handleClick() {
        var code = $("#codeName").val();
        if (code == null || code == "" || code.length != 6) {
            if (code.length != 6) {
                swal({title: "请输入正确的股票代码", text: ""});
            } else {
                swal({title: "请输入股票代码", text: ""});
            }
        } else {
            if (code.startsWith("6", 0)) {
                code = "sh" + code;
            } else {
                code = "sz" + code;
            }
            $.ajax({
                url: '/ajaxRequest',
                type: "get",
                data: {"code": code},
                success: function (data) {
                    var code1 = $.parseJSON(data);
                    var code = code1.code;
                    swal({title: code1.gpname, text: "添加成功"});
                   // var desc = prompt("请输入备注描述：", code1.gpname);
                    var desc =code1.gpname;
                        $("#addCode").val(code);
                    $("#addDesc").val(desc);
                    handleClickAjax(code, desc);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    swal({title: "查询失败，请检查股票代码！", text: ""});
                },
            });
        }
    }

    /**
     * 添加
     * @param code
     * @param desc
     */
    function handleClickAjax(code, desc) {
        $.ajax({
            url: '/addStock',
            type: "get",
            data: {"code": code, "desc": desc},
            success: function (data) {
                window.location.reload();
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                swal({title: "查询失败，请检查股票代码！", text: ""});
            },
        });
    }

</script>
</body>

</html>